package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.pojo.*;
import com.econ.powercloud.ems.pojo.requestVO.EmsWarnPidEditVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsWarnPidRequestVO;
import com.econ.powercloud.ems.service.biz.EmsWarnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/12/2 11:25
 * @Modified by : zjf
 */
@Api(tags = "诊断预警")
@RestController
@RequestMapping("/api/v2/warn")
public class EmsWarnController extends ApiBaseController{

    @Autowired
    private EmsWarnService emsWarnService;

    @ApiOperation(value = "获取诊断预警列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceCode", required = false,value = "设备编号", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "isAsc", value = "是否升序", dataType = "boolean"),
            @ApiImplicitParam(paramType = "query", name = "sortField", value = "排序字段(见枚举)", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页大小", dataType = "int"),
    })
    @GetMapping
    public MsgResult<PageResult<List<EmsWarnStatisticalVO>>> get(@RequestParam(value = "deviceCode",required = false) String deviceCode,
                                                                        @RequestParam("isAsc") boolean isAsc, @RequestParam("sortField") Integer sortField,
                                                                        @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return this.successHandler(emsWarnService.getWarnStatisticalData(deviceCode, isAsc, sortField, pageNo, pageSize));
    }

    @ApiOperation(value = "预警点号历史数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceCode", value = "设备编号", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", dataType = "long"),
    })
    @GetMapping("getWarnPidHisData")
    public MsgResult<List<EmsWarnHisChartDataVO>> getWarnPidHisData(@RequestParam("deviceCode")String deviceCode,
                                                                    @RequestParam("startTime")Long startTime,
                                                                    @RequestParam("endTime")Long endTime){
        return successHandler(emsWarnService.getWarnPidHisData(deviceCode, startTime, endTime));
    }

    @ApiOperation(value = "查询单个预警点号")
    @GetMapping("selectWarnPidById")
    public MsgResult<EmsWarnConfigVO> selectWarnPidById(@RequestParam("id")Integer id){
        return successHandler(emsWarnService.selectWarnPidById(id));
    }

    @ApiOperation(value = "新增预警点号")
    @PostMapping("addWarnPid")
    public MsgResult addWarnPid(@RequestBody @Validated EmsWarnPidRequestVO requestVO){
        emsWarnService.addWarnPid(requestVO);
        return successHandler(true);
    }

    @ApiOperation(value = "修改预警点号")
    @PutMapping("modifyWarnPid")
    public MsgResult modifyWarnPid(@RequestBody @Validated EmsWarnPidEditVO editVO){
        emsWarnService.modifyWarnPid(editVO);
        return successHandler(true);
    }

    @ApiOperation(value = "删除预警点号")
    @DeleteMapping("deleteWarnPid")
    public MsgResult deleteWarnPid(Integer id){
        emsWarnService.deleteWarnPid(id);
        return successHandler(true);
    }

    @ApiOperation(value = "获取诊断预警点号记录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceCode", value = "设备编号", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "name", value = "点号名称", dataType = "String",required = false),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页大小", dataType = "int"),
    })
    @GetMapping("getWarnRecord")
    public MsgResult<PageResult<List<EmsWarnRecordVO>>> getWarnRecord(@RequestParam(value = "deviceCode") String deviceCode,
                                                                      @RequestParam(value = "name",required = false)String name,
                                                                      @RequestParam("startTime") Long startTime, @RequestParam("endTime") Long endTime,
                                                                      @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return this.successHandler(emsWarnService.selectWarnRecord(deviceCode, name, startTime, endTime, pageNo, pageSize));
    }

    @ApiOperation(value = "初始化预警统计与配置表")
    @PostMapping("initWarnStatisticalData")
    public MsgResult initWarnStatisticalData(@RequestBody List<InitWarnStatisticalRequestVO> requestVOList){
        emsWarnService.initWarnStatisticalData(requestVOList);
        return successHandler(true);
    }
}
